package uix

import (
	"fmt"
	"github.com/fzdwx/infinite"
	"github.com/fzdwx/infinite/components/input/text"
	"github.com/fzdwx/infinite/theme"
)

func Input(title string) string {
	return InputWithDefault(title, "")
}

func InputWithDefault(title, defaultValue string) string {
	if defaultValue != "" {
		title = fmt.Sprintf("%v [%v]", title, defaultValue)
	}
	t := infinite.NewText(
		text.WithPrompt(title),
		text.WithPromptStyle(theme.DefaultTheme.PromptStyle),
	)
	val, _ := t.Display()
	if val == "" {
		return defaultValue
	}
	return val
}
